//Stores the url
#ifndef URLCLASS
#define URLCLASS
#include<string>
#include "UnitTest.h"

using namespace std;
const string File("file:");
const string Http("http://");



class Url {


public:


//! @param Constructor: Takes a url and it's starting address (for relative) and stores the Url in it's different parts and resolves relative
    Url(const string Url,const string BaseUrl);

//! @param Constructor: Takes a url string and will assume it is absolute. If it is not, it will not parse correctly anyway
    Url(const string Url);




    //! Getters

    string GetFull		()const;
    string GetScheme		()const;
    string GetNet_Loc		()const;
    string GetPath		()const;
    string GetParam		()const;
    string GetQuery		()const;
    string GetFragment		()const;
    string GetBaseUrl(const Url Path)const;

    //! @return true if there is a description
    bool IsUrl()const;
//! @Return true if GetScheme equals http://
    bool IsHttp();
//! @Return true if GetScheme equals file:
    bool IsFile();
//! @Return true if either IsHttp or IsFile is true
    bool IsValid();
//! @Returns a string representation of the object
    string ToString() const;

    static bool Test(ostream & os);

private:
//!  Parts of the url
    string Scheme;
    string Net_Loc;
    string Path;
    string Param;
    string Query;
    string Fragment;

//	UrlChecker checker;	//used to check if a given url is a URL
//! @param Parses the URL into it's parts
    void ParseUrl	(const string Url);
//! @Returns true if the given url is obsolute
    bool IsAbsolute (string Url) const;
//! @Param Resolves Url according to the base url
    void Resolve    (string & Url, const string BaseUrl);


//! @Param Used by the constructors to construct the class. Takes a relative url string and base url string
    void Construct (const string Url,const string BaseUrl);

//! These next set of functions are the parse methods for the Url class.
//! Each one takes a pointer to an index integer and a char[] and
//! parses it and changes the interger to the index of where it left off
private:
    void ParseScheme  (const char * Url , int & Index);
    void ParseNet     (const char * Url , int & Index);
    void ParsePath    (const char * Url , int & Index);
    void ParseParam   (const char * Url , int & Index);
    void ParseQuery   (const char * Url , int & Index);
    void ParseFragment(const char * Url , int & Index);

//! @Return a charcter in a string object based on the char[] and the index
    string GetNext	  (const char * Url ,const int & Index);

//! Part of resolving a url. It handles the dots in a file extension
//! @param The path to resovle the dots
//! @return the string with the resolved dots
    string ResolveDots(const string & path);









};


#endif
